function ajax(options) {
	options = options || {};
	options.type = options.type||'GET';
	options.data = options.data||{};
	options.dataType = options.dataType||'text';
	let xhr = new XMLHttpRequest();

	let arr =[];
	for(let key in options.data){
		arr.push(`${key}=${options.data[key]}`)
	}
	let strData = arr.join('&');
	if(options.type=='POST'){
		xhr.open('POST',options.url,true);
		xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
		xhr.send(strData)
	}else{
		xhr.open('GET',options.url+'?'+strData,true);
		xhr.send()
	}
	xhr.onreadystatechange =function () {
		if(xhr.readyState==4){
			if(xhr.status==200){
				let data = xhr.responseText;
				switch (options.dataType){
					case 'json':
						data = JSON.parse(data);
						break;
					case 'text':
						break;
				}
				options.success&&options.success(data)
			}else{
				options.error&&options.error();
			}
		}
	}

}